package mt.tests;

import java.util.LinkedList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


import mt.Order;
import mt.comm.ClientComm;
import mt.comm.ServerComm;
import mt.server.MicroTraderServerDummy;

public class TestServer {
	private LinkedList<String> clients = new LinkedList<String>();
	private LinkedList<String> clientsOnline = new LinkedList<String>();
	private LinkedList<Order> sellingOrders = new LinkedList<Order>();
	private LinkedList<Order> buyingOrders = new LinkedList<Order>();
	private ServerComm serverComm;
	private TestServerComm testServerComm;
	private ClientComm clientComm;
	private MicroTraderServerDummy server = new MicroTraderServerDummy();
	private Order order;
	mt.comm.ServerSideMessage.Type connected = mt.comm.ServerSideMessage.Type.CONNECTED;
	mt.comm.ServerSideMessage.Type disconnected = mt.comm.ServerSideMessage.Type.DISCONNECTED;
	mt.comm.ServerSideMessage.Type new_order = mt.comm.ServerSideMessage.Type.NEW_ORDER;
	
	@Before
	public void setUp() throws Exception {

	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testSortMessage() {
		TestServerSideMessage m1 = new TestServerSideMessage(connected, "Joao", null); 
		TestServerSideMessage m2 = new TestServerSideMessage(connected, "Andre", null); 
		TestServerSideMessage m3 = new TestServerSideMessage(disconnected, "Andre", null); 
		server.sortMessage(m1);
		server.sortMessage(m2);
		server.sortMessage(m3);
	}
	
	@Test
	public void testSortMessageWithOrder() {
		Order order = Order.createBuyOrder("Rodrigo", "RT", 10, 6);
		TestServerSideMessage m1 = new TestServerSideMessage(new_order, "Rodrigo", order); 
		server.sortMessage(m1);
	}
	
	@Test
	public void testTreatClient() {
		MicroTraderServerDummy server = new MicroTraderServerDummy();
		TestServerSideMessage m1 = new TestServerSideMessage(connected, "Joao", null); 
		TestServerSideMessage m2 = new TestServerSideMessage(connected, "Joao", null); 
		server.sortMessage(m1);
		server.sortMessage(m2);
		
	}
	
	@Test
	public void testTreatBuyOrderPossibleToBuyAndSatisfied() {
		TestServerSideMessage c = new TestServerSideMessage(connected, "Joao", null); 
		TestServerSideMessage c2 = new TestServerSideMessage(connected, "Rodrigo", null); 
		server.sortMessage(c);
		server.sortMessage(c2);
		
		Order order1 = Order.createSellOrder("Rodrigo", "RT", 10, 6);
		TestServerSideMessage m1 = new TestServerSideMessage(new_order, "Rodrigo", order1); 
		server.sortMessage(m1);
		
		Order order2 = Order.createBuyOrder("Joao", "RT", 10, 6);
		TestServerSideMessage m2 = new TestServerSideMessage(new_order, "Joao", order2); 
		server.sortMessage(m2);
		
		Order order3 = Order.createBuyOrder("Joao", "RT", 10, 6);
		TestServerSideMessage m3 = new TestServerSideMessage(new_order, "Joao", order3); 
		server.sortMessage(m3);
	}
}
